<template>
  <div id="app">
    <router-view></router-view>
    <!-- <router-view v-if="isShow"></router-view> -->
  </div>
</template>

<script>
import { dingTalkM } from "./auth/dingtalk-auth";

export default {
  name: "app",
  data: function() {
    return {
      // isShow: false,
      //通过之后，显示
      //  isBoolen: false,
    };
  },
  // created: function() {
  //   let _self = this;
  //   dd.ready(function() {
  //     _self.isShow = true;
  //   })
  // }
  methods: {
    // 钉钉签名，免登调用
    authSerivce: function() {
      //JSAPILIST功能注册
      let ddjsApi = [
        "device.notification.alert",
        "device.notification.confirm",
        "runtime.permission.requestOperateAuthCode",
        "biz.util.uploadImage",
        "biz.contact.choose",
        "device.geolocation.get",
        "biz.util.share",
        "biz.ding.post",
        "biz.user.get",
        "biz.navigation.setLeft",
        "biz.util.uploadImageFromCamera",
        "device.screen.rotateView",
        "device.screen.resetView",
        "biz.util.datepicker"
      ];

      return new Promise(function(resolve, reject) {
        dingTalkM.ddConfig(ddjsApi, "api/auth/getJsConfig").then(resCorpid => {
          localStorage.setItem("corpId", resCorpid);
          dd.ready(function() {
            dingTalkM.authLogin(resCorpid, "api/auth/login").then(
              token => {
                //设置HTTP.Header值
                localStorage.setItem("authorization", token.token);
                resolve(1);
              },
              err => {
                alert(JSON.stringify(err));
              }
            );
          });

          dd.error(function(res) {
            alert(JSON.stringify(res));
          });
        });
      });
    }
  },

  created: function() {
    // this.$router.replace("/Home");
    //钉钉软件内路由跳转
    //钉钉内首页路由跳转，签名，免登；
     this.authSerivce().then(res => {
    //   console.log("============");
      this.$router.replace("/Home");
     });
  }
};
</script>
